| Conditions | 1 |
| Paths | 4 |
| Total Lines | 228 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.
There are several approaches to avoid long parameter lists:
| 1 | /* |
||
| 23 | app.controller('BoardController', function ($rootScope, $scope, $stateParams, StatusService, BoardService, StackService, CardService, LabelService, $state, $transitions, $filter) { |
||
| 24 | |||
| 25 | $scope.sidebar = $rootScope.sidebar; |
||
| 26 | |||
| 27 | $scope.id = $stateParams.boardId; |
||
| 28 | $scope.status = { |
||
| 29 | addCard: [], |
||
| 30 | }; |
||
| 31 | $scope.newLabel = {}; |
||
| 32 | $scope.status.boardtab = $stateParams.detailTab; |
||
| 33 | |||
| 34 | $scope.stackservice = StackService; |
||
| 35 | $scope.boardservice = BoardService; |
||
| 36 | $scope.cardservice = CardService; |
||
| 37 | $scope.statusservice = StatusService.getInstance(); |
||
| 38 | $scope.labelservice = LabelService; |
||
| 39 | $scope.defaultColors = ['31CC7C', '317CCC', 'FF7A66', 'F1DB50', '7C31CC', 'CC317C', '3A3B3D', 'CACBCD']; |
||
| 40 | |||
| 41 | $scope.search = function (searchText) { |
||
| 42 | $scope.searchText = searchText; |
||
| 43 | $scope.refreshData(); |
||
| 44 | }; |
||
| 45 | |||
| 46 | $scope.board = BoardService.getCurrent(); |
||
| 47 | StackService.clear(); //FIXME: Is this still needed? |
||
| 48 | $scope.statusservice.retainWaiting(); |
||
| 49 | $scope.statusservice.retainWaiting(); |
||
| 50 | |||
| 51 | // FIXME: ugly solution for archive |
||
| 52 | $scope.$state = $stateParams; |
||
| 53 | $scope.filter = $stateParams.filter; |
||
| 54 | $scope.$watch('$state.filter', function (name) { |
||
| 55 | $scope.filter = name; |
||
| 56 | }); |
||
| 57 | $scope.switchFilter = function (filter) { |
||
| 58 | $state.go('.', {filter: filter}, {notify: false}); |
||
| 59 | $scope.filter = filter; |
||
| 60 | }; |
||
| 61 | $scope.$watch('filter', function (name) { |
||
| 62 | if (name === "archive") { |
||
| 63 | $scope.loadArchived(); |
||
| 64 | } else { |
||
| 65 | $scope.loadDefault(); |
||
| 66 | } |
||
| 67 | }); |
||
| 68 | |||
| 69 | |||
| 70 | $scope.stacksData = StackService; |
||
| 71 | $scope.stacks = {}; |
||
| 72 | $scope.$watch('stacksData', function (value) { |
||
|
|
|||
| 73 | $scope.refreshData(); |
||
| 74 | }, true); |
||
| 75 | $scope.refreshData = function () { |
||
| 76 | if ($scope.filter === "archive") { |
||
| 77 | $scope.filterData('-lastModified', $scope.searchText); |
||
| 78 | } else { |
||
| 79 | $scope.filterData('order', $scope.searchText); |
||
| 80 | } |
||
| 81 | }; |
||
| 82 | $scope.checkCanEdit = function () { |
||
| 83 | return !$scope.archived; |
||
| 84 | }; |
||
| 85 | |||
| 86 | // filter cards here, as ng-sortable will not work nicely with html-inline filters |
||
| 87 | $scope.filterData = function (order, text) { |
||
| 88 | if ($scope.stacks === undefined) |
||
| 89 | return; |
||
| 90 | angular.copy(StackService.getAll(), $scope.stacks); |
||
| 91 | angular.forEach($scope.stacks, function (value, key) { |
||
| 92 | var cards = $filter('cardSearchFilter')(value.cards, text); |
||
| 93 | cards = $filter('orderBy')(cards, order); |
||
| 94 | $scope.stacks[key].cards = cards; |
||
| 95 | }); |
||
| 96 | }; |
||
| 97 | |||
| 98 | $scope.loadDefault = function () { |
||
| 99 | StackService.fetchAll($scope.id).then(function (data) { |
||
| 100 | $scope.statusservice.releaseWaiting(); |
||
| 101 | }, function (error) { |
||
| 102 | $scope.statusservice.setError('Error occured', error); |
||
| 103 | }); |
||
| 104 | }; |
||
| 105 | |||
| 106 | $scope.loadArchived = function () { |
||
| 107 | StackService.fetchArchived($scope.id).then(function (data) { |
||
| 108 | $scope.statusservice.releaseWaiting(); |
||
| 109 | }, function (error) { |
||
| 110 | $scope.statusservice.setError('Error occured', error); |
||
| 111 | }); |
||
| 112 | }; |
||
| 113 | |||
| 114 | // Handle initial Loading |
||
| 115 | BoardService.fetchOne($scope.id).then(function (data) { |
||
| 116 | BoardService.getPermissions(); |
||
| 117 | $scope.statusservice.releaseWaiting(); |
||
| 118 | }, function (error) { |
||
| 119 | $scope.statusservice.setError('Error occured', error); |
||
| 120 | }); |
||
| 121 | |||
| 122 | BoardService.searchUsers('%25'); |
||
| 123 | |||
| 124 | $scope.searchForUser = function (search) { |
||
| 125 | if (search == "") { |
||
| 126 | search = "%25"; |
||
| 127 | } |
||
| 128 | BoardService.searchUsers(search); |
||
| 129 | }; |
||
| 130 | |||
| 131 | $scope.newStack = {'boardId': $scope.id}; |
||
| 132 | $scope.newCard = {}; |
||
| 133 | |||
| 134 | // Create a new Stack |
||
| 135 | $scope.createStack = function () { |
||
| 136 | StackService.create($scope.newStack).then(function (data) { |
||
| 137 | $scope.newStack.title = ""; |
||
| 138 | }); |
||
| 139 | }; |
||
| 140 | |||
| 141 | $scope.createCard = function (stack, title) { |
||
| 142 | var newCard = { |
||
| 143 | 'title': title, |
||
| 144 | 'stackId': stack, |
||
| 145 | 'type': 'plain' |
||
| 146 | }; |
||
| 147 | CardService.create(newCard).then(function (data) { |
||
| 148 | $scope.stackservice.addCard(data); |
||
| 149 | $scope.newCard.title = ""; |
||
| 150 | }); |
||
| 151 | }; |
||
| 152 | |||
| 153 | $scope.cardDelete = function (card) { |
||
| 154 | CardService.delete(card.id); |
||
| 155 | StackService.removeCard(card); |
||
| 156 | }; |
||
| 157 | $scope.cardArchive = function (card) { |
||
| 158 | CardService.archive(card); |
||
| 159 | StackService.removeCard(card); |
||
| 160 | }; |
||
| 161 | $scope.cardUnarchive = function (card) { |
||
| 162 | CardService.unarchive(card); |
||
| 163 | StackService.removeCard(card); |
||
| 164 | }; |
||
| 165 | |||
| 166 | $scope.labelDelete = function (label) { |
||
| 167 | LabelService.delete(label.id); |
||
| 168 | // remove from board data |
||
| 169 | var i = BoardService.getCurrent().labels.indexOf(label); |
||
| 170 | BoardService.getCurrent().labels.splice(i, 1); |
||
| 171 | // TODO: remove from cards |
||
| 172 | }; |
||
| 173 | $scope.labelCreate = function (label) { |
||
| 174 | label.boardId = $scope.id; |
||
| 175 | LabelService.create(label); |
||
| 176 | BoardService.getCurrent().labels.push(label); |
||
| 177 | $scope.status.createLabel = false; |
||
| 178 | $scope.newLabel = {}; |
||
| 179 | }; |
||
| 180 | $scope.labelUpdate = function (label) { |
||
| 181 | label.edit = false; |
||
| 182 | LabelService.update(label); |
||
| 183 | }; |
||
| 184 | |||
| 185 | $scope.aclAdd = function (sharee) { |
||
| 186 | sharee.boardId = $scope.id; |
||
| 187 | BoardService.addAcl(sharee); |
||
| 188 | $scope.status.addSharee = null; |
||
| 189 | }; |
||
| 190 | $scope.aclDelete = function (acl) { |
||
| 191 | BoardService.deleteAcl(acl); |
||
| 192 | }; |
||
| 193 | $scope.aclUpdate = function (acl) { |
||
| 194 | BoardService.updateAcl(acl); |
||
| 195 | }; |
||
| 196 | |||
| 197 | |||
| 198 | // settings for card sorting |
||
| 199 | $scope.sortOptions = { |
||
| 200 | itemMoved: function (event) { |
||
| 201 | event.source.itemScope.modelValue.status = event.dest.sortableScope.$parent.column; |
||
| 202 | var order = event.dest.index; |
||
| 203 | var card = event.source.itemScope.c; |
||
| 204 | var newStack = event.dest.sortableScope.$parent.s.id; |
||
| 205 | var oldStack = card.stackId; |
||
| 206 | card.stackId = newStack; |
||
| 207 | CardService.update(card); |
||
| 208 | CardService.reorder(card, order).then(function (data) { |
||
| 209 | StackService.addCard(card); |
||
| 210 | StackService.reorder(card, order); |
||
| 211 | StackService.removeCard({ |
||
| 212 | id: card.id, |
||
| 213 | stackId: oldStack |
||
| 214 | }); |
||
| 215 | }); |
||
| 216 | }, |
||
| 217 | orderChanged: function (event) { |
||
| 218 | var order = event.dest.index; |
||
| 219 | var card = event.source.itemScope.c; |
||
| 220 | var stack = event.dest.sortableScope.$parent.s.id; |
||
| 221 | CardService.reorder(card, order).then(function (data) { |
||
| 222 | StackService.reorder(card, order); |
||
| 223 | $scope.refreshData(); |
||
| 224 | }); |
||
| 225 | }, |
||
| 226 | scrollableContainer: '#board', |
||
| 227 | containerPositioning: 'relative', |
||
| 228 | containment: '#board', |
||
| 229 | // auto scroll on drag |
||
| 230 | dragMove: function (itemPosition, containment, eventObj) { |
||
| 231 | if (eventObj) { |
||
| 232 | var container = $("#board"); |
||
| 233 | var offset = container.offset(); |
||
| 234 | var targetX = eventObj.pageX - (offset.left || container.scrollLeft()); |
||
| 235 | var targetY = eventObj.pageY - (offset.top || container.scrollTop()); |
||
| 236 | if (targetX < offset.left) { |
||
| 237 | container.scrollLeft(container.scrollLeft() - 50); |
||
| 238 | } else if (targetX > container.width()) { |
||
| 239 | container.scrollLeft(container.scrollLeft() + 50); |
||
| 240 | } |
||
| 241 | if (targetY < offset.top) { |
||
| 242 | container.scrollTop(container.scrollTop() - 50); |
||
| 243 | } else if (targetY > container.height()) { |
||
| 244 | container.scrollTop(container.scrollTop() + 50); |
||
| 245 | } |
||
| 246 | } |
||
| 247 | } |
||
| 248 | }; |
||
| 249 | |||
| 250 | }); |
||
| 251 |
This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.